define(['jquery', 'lodash', 'lodash_fp', 'app/utils', 'chains', 'maybe'], ($, _, fp, U, chains,M) => {

  (async function start() {
    chains.global({
      params: new URLSearchParams(window.location.search)
    }).chains((_,global) => global.params.has('id') ? M.just(global.params.get('id')) : M.nothing(),get_foods,render_foods)
  }())
  

  //get_foods : Maybe String -> List Food
  function get_foods(maybe_id) {
    let foods = []
    if (M.isJust(maybe_id)) {
      $.get({
        url: '/user-end/shop/' + M.value(maybe_id),
        async: false,
        success: res => {
          if (U.is_res_ok(res)) {
            foods = U.result(res)
          } else {
            alert('获取商店信息出错' + (U.is_empty_string(U.error(res)) ? '' : U.error(res)))
          }
        }
      })
    } else {
      alert('请传入商店ID')
    }
    return foods
  }

  //render_foods : List Foods -> ()
  function render_foods(foods) {
    _.map(foods, food => {
      $('#food_list').append(`<a class="collection-item" href="/pages/user-end/food.html?id=${food.id}">${food.name}: ${food.price}元</a>`)
    })
    return null
  }

})